/**
 * 用户反馈
 * @author zhangqiang
 * @date   2016/09/29
 */

(function (lf, r) {

    var RC = r.createClass,
        ajax = lf.utils.ajax;

    var Body = RC({
        getInitialState: function () {
            return ({
                len: {},
                waing: [],
                isShow: false,
            })
        },
        componentWillMount(){
            var me = this,
                user = me.props.user;

            ajax({
                type: 'post',
                data: {
                    projectId: user.projectId,
                    houseId: user.houseId,
                    userId: user.userId,
                },
                success: function (data) {
                    var ber = data.data.number,
                        $text_cell = $(".wait"),
                        $text_file = $(".wait-add");
                    me.setState({
                        len: data.data
                    });
                    $text_file.text(ber)
                }
            }, '/api/finger/household/getCheckinQueue')


            ajax({
                type: 'post',
                data: {
                    projectId: user.projectId,
                    houseId: user.houseId,
                    userId: user.userId,
                },
                success: function (res) {
                    var $list_box = $('.list_box');

                    var fmt = 'yyyy-MM-dd hh:mm';
                    
                    if (res.dataList.length == 0) {
                        $('.img-add').css({display: "block"});
                        me.setState({
                            isShow: true,
                        })
                    }

                    $(res.dataList).each(function (i, item) {
                        var ben = res.dataList[i].status;
                        var figure = res.dataList.length - i;
                        if (res.dataList.length == 0) {
                            $('.img-add').css({display: "block"});
                            me.setState({
                                isShow: true,
                            })
                        } else {
                            var Time = lf.utils.format(res.dataList[i].createTime, fmt);
                            let num = figure <= 9 ? '0' + figure : figure;

                            let text = ben == 1 ? '号办理中!' : ben == 2 ? '号办理成功!' : null;
                            ben != 0 ?
                                $list_box.append("<ul class='box-waited'><li><span><i>" + num +
                                    "</i>  <span class='show'>" + text
                                    + "</span> </span></li><li>" + Time + "</li></ul>") :
                                null;
                        }
                    })
                }
            }, '/api/finger/household/getCheckinQueueList')
        },


        render: function () {
            var inti = this.state.len;
            return (
                <div className="box-mic">
                    <div className="box">
                        <ul>
                            <li>
                                <p>当前办理号</p>
                                <p className="text-main">{inti.nowSeq ? inti.nowSeq : "无"}</p>
                            </li>
                            <li>
                                <p>您的排队号</p>
                                <p>{inti.seq}</p>
                            </li>
                        </ul>
                        <div className="wait">还需等待 <span className="wait-add"> 0 </span> 人</div>
                    </div>
                    <div className="box-add">
                        详情
                    </div>
                    <div className="list_box">
                        <div className={"img-add " + (this.state.isShow?'show':'')}>
                            <p className="img-lost"><img src="../public/images/finger/lost.png"/></p>
                            <p>恭喜抢到沙发，赶紧前去办理</p>
                            <p className="text-no">不清楚办理流程?</p>
                            <p className="img-look"><img src="../public/images/finger/look.png"/></p>
                        </div>
                    </div>
                </div>
            )
        }
    });

    lf.bridgeJs.getUser(function (user) {
        lf.appJs.setTitle('入住办理动态');
        r.render(
            <Body user={user}/>,
            document.getElementById('root'), function () {
                $('#root').css('background', '#fff');
            }
        )
    })

})(liefeng, React)

